package uestc.lj.basicPromotion.bitmap;

/**
 * 位图
 *
 * @Author:Crazlee
 * @Date:2021/11/25
 */
public class Code01_BitMap {
	public static void main(String[] args) {
		// a 32 bit
		int a = 0;

		/**
		 * 32bit * 10 ——> 320 bits
		 * arr[0] int 0~31
		 * arr[1] int 32~63
		 */
		int[] arr = new int[10];

		//想取得第178个bit的状态
		int i = 178;

		int numIndex = i / 32;
		int bitIndex = i % 32;

		//拿到第i位的状态
		int s = ((arr[numIndex] >> bitIndex) & 1);

		//将第i位的状态改为1
		arr[numIndex] = arr[numIndex] | (1 << bitIndex);

		//将第i位的状态改为0
		arr[numIndex] = arr[numIndex] & (~(1 << bitIndex));

	}
}
